<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from '@/views/dashboard/mixins/resize.js'

const animationDuration = 6000

export default {
  mixins: [resize],
  props: {
    data:{
       type: Array,
       default:[]
    },
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '100%'
    },
    height: {
      type: String,
      default: '300px'
    }
  },
  data() {
    return {
      chart: null
    }
  },
  mounted() {
    this.$nextTick(() => {
      this.initChart()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons')

      this.chart.setOption({
    xAxis: {
        type: 'category',
        data:  this.data[0]
    },
    yAxis: {
        type: 'value'
    },
    series: [
      {
        data: this.data[1],
        type: 'bar',
        showBackground: true,
        backgroundStyle: {
            color: 'rgba(220, 220, 220, 0.8)'
        }
    },
      {
        data: this.data[2],
        type: 'bar',
        showBackground: true,
        backgroundStyle: {
            color: 'rgba(200, 200, 200, 0.8)'
        }
    }
    ]
})
    }
  }
}
</script>
